package com.zhss.microservice.server.node;

import com.zhss.microservice.server.registry.ServiceInstance;
import com.zhss.microservice.server.registry.ServiceRegistry;

/**
 * 槽位
 */
public class Slot {

    /**
     * 槽位编号
     */
    private Integer slotNo;
    /**
     * 服务注册表
     */
    private ServiceRegistry serviceRegistry;

    /**
     * 构造函数
     * @param slotNo
     */
    public Slot(Integer slotNo) {
        this.slotNo = slotNo;
        this.serviceRegistry = ServiceRegistry.getInstance();
    }

    /**
     * 注册服务实例
     */
    public void register(ServiceInstance serviceInstance) {
        serviceRegistry.register(serviceInstance);
    }

    /**
     * 服务实例进行心跳
     * @param serviceName
     * @param serviceInstanceIp
     * @param serviceInstancePort
     */
    public void heartbeat(String serviceName,
                          String serviceInstanceIp,
                          Integer serviceInstancePort) {
        serviceRegistry.heartbeat(serviceName, serviceInstanceIp, serviceInstancePort);
    }

}
